/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.scene.controller;


import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.scene.bean.StdJobs;
import com.koron.scene.service.api.StdJobsCertificateService;
import com.koron.scene.utils.BusinessCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "stdJobsCertificate", description = "标准岗位证书")
@RestController
@RequestMapping("/stdJobsCertificate")
public class StdJobsCertificateController {

    @Autowired
    private StdJobsCertificateService stdJobsCertificateService;

    @ApiOperation("获取岗位证照列表(证照)")
    @ApiImplicitParams({
    })
    @RequestMapping(value = "/list.htm", method = RequestMethod.GET)
    public MessageBean<?> list(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user) {
        if (user == null) {
            MessageBean<?> msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return stdJobsCertificateService.list();
    }

    @ApiOperation("根据stdJobId获取岗位证照")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stdJobId", value = "岗位工种Id", required = false, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/queryById.htm", method = RequestMethod.GET)
    public MessageBean<StdJobs> queryById(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String stdJobId) {
        if (user == null) {
            MessageBean<StdJobs> msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return stdJobsCertificateService.queryById(stdJobId);
    }

    @ApiOperation("根据stdJobId获取岗位证照")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stdJobId", value = "岗位工种Id", required = false, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/queryById.htm", method = RequestMethod.POST)
    public MessageBean<?> save(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestBody StdJobs stdJob) {
        if (user == null) {
            MessageBean<?> msg = new MessageBean();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return stdJobsCertificateService.save(user, stdJob);
    }

}
